package com.lk.demo.controller;

import com.lk.demo.model.Author;
import com.lk.demo.repos.AuthorRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/author")
public class AuthorController {
    private final AuthorRepository authorService;

    @Autowired
    public AuthorController(AuthorRepository authorService) {
        this.authorService = authorService;
    }

    @GetMapping("/{id}")
    public Author get(@PathVariable Long id)
    {
        return authorService.findById(id).orElse(null);
    }

    @PostMapping
    public Author save(@RequestBody Author author)
    {
        return authorService.save(author);
    }
    @DeleteMapping("/{id}")
    public String delete(@PathVariable Long id)
    {
        authorService.deleteById(id);
        return "success";
    }
}
